package com.speak.sparkadminserver.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.speak.sparkadminserver.dao.NutRoleDao;
import com.speak.sparkadminserver.dao.NutRolePowerDao;
import com.speak.sparkadminserver.domain.NutRolePower;
import com.speak.sparkadminserver.service.NutRolePowerService;
import com.speak.sparkadminserver.service.NutRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @version 1.0
 * @Author Xing
 * @Date 2023/2/21 4:08
 */
@Service
public class NutRolePowerServiceImpl extends
        ServiceImpl<NutRolePowerDao,NutRolePower> implements NutRolePowerService {
    @Autowired
    private NutRolePowerDao dao;
    @Autowired
    private NutRoleDao roleDao;

    @Override
    public List<Integer> AuthList(Long userId) {
        List<Long> role = roleDao.getRole(userId);
        List<Integer> powers = new ArrayList<>();
        for (Long aLong : role) {
            List<Integer> integers = dao.AuthList(aLong);
            powers.addAll(integers);
        }
        return powers;
    }

    @Override
    public void Save(Long roleId) {
        NutRolePower power = new NutRolePower();
        power.setRoleId(roleId);
        power.setPower(3);
        power.setCreateTime(new Date());
        power.setUpdateTime(new Date());
        super.save(power);
    }
}
